﻿using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using StockholmsStad.Windows.UI.Infrastructure.Windows;
using StockholmsStad.Windows.UI.Modules.Ceremony.Events;
using StockholmsStad.Windows.UI.Modules.Ceremony.Models;
using Microsoft.Practices.Composite.Events;

namespace StockholmsStad.Windows.UI.Modules.Ceremony.Controls
{
    /// <summary>
    /// Interaction logic for CeremonyPreviousDetailsControl.xaml
    /// </summary>
    public partial class CeremonyPreviousDetailsControl
    {
        private IEventAggregator eventAggregator;

        public CeremonyPreviousDetailsControl()
        {
            InitializeComponent();
        }
        public IEventAggregator Aggregator
        {
            set { eventAggregator = value; }
        }

        public ObservableCollection<CeremonyDetailsPresentationModel> Model
        {
            get { return DataContext as ObservableCollection<CeremonyDetailsPresentationModel>; }
            set { DataContext = value; }
        }

        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            var button = e.Source as Button;

            if (button != null)
            {
                var ceremony = button.DataContext as CeremonyDetailsPresentationModel;

                // Öppna printdialog

                var printSelector = new PrintSelector { Model = ceremony };
                var modalWindow = new GenericModalWindow { GenericContent = printSelector };
                modalWindow.ShowDialog();
            }
        }

        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            Mouse.OverrideCursor = Cursors.Wait;
            eventAggregator.GetEvent<UpdateTicketsWithStatus>().Publish(Model);
            Mouse.OverrideCursor = null;
        }
    }
}